using FireStarterModeller.UI;
using Habanero.Faces.Base;
using Habanero.Faces.Win;
using NUnit.Framework;

namespace FireStarterModeller.Test.UI.CodeGeneration
{
    [TestFixture]
    public class TestProjectNameControl
    {
        [TestFixtureSetUp]
        public void SetUpFixture()
        {
            GlobalUIRegistry.ControlFactory = new ControlFactoryWin();
        }

        [Test]
        public void Test_ProjectNameControl_BasicLayout()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            ProjectNames projectName = TestUtilsShared.GetRandomEnum<ProjectNames>();
            ProjectNameControl projectNameControl = new ProjectNameControl(projectName);
            //---------------Test Result -----------------------
            Assert.AreEqual(3, projectNameControl.Controls.Count);

            Assert.IsInstanceOf(typeof(ILabel), projectNameControl.Controls[0]);
            Assert.IsInstanceOf(typeof(ITextBox), projectNameControl.Controls[1]);
            Assert.IsInstanceOf(typeof(ICheckBox), projectNameControl.Controls[2]);

            Assert.AreSame(projectNameControl.Label, projectNameControl.Controls[0]);
            Assert.AreSame(projectNameControl.TextBox, projectNameControl.Controls[1]);
            Assert.AreSame(projectNameControl.CheckBox, projectNameControl.Controls[2]);

            Assert.AreEqual(200, projectNameControl.Label.Width);
            Assert.AreEqual(projectName.ToString().Replace("_", " "), projectNameControl.Label.Text);
            Assert.IsFalse(projectNameControl.CheckBox.Checked);
            Assert.AreEqual("", projectNameControl.TextBox.Text);
            Assert.IsFalse(projectNameControl.TextBox.Enabled);
        }

        [Test]
        public void Test_CheckBox_On()
        {
            //---------------Set up test pack-------------------
            ProjectNameControl projectNameControl = new ProjectNameControl(TestUtilsShared.GetRandomEnum<ProjectNames>());
            //---------------Assert Precondition----------------
            Assert.IsFalse(projectNameControl.TextBox.Enabled);
            //---------------Execute Test ----------------------
            projectNameControl.CheckBox.Checked = true;
            //---------------Test Result -----------------------
            Assert.IsTrue(projectNameControl.TextBox.Enabled);
        }

        [Test]
        public void Test_CheckBox_Off()
        {
            //---------------Set up test pack-------------------
            ProjectNameControl projectNameControl = new ProjectNameControl(TestUtilsShared.GetRandomEnum<ProjectNames>());
            projectNameControl.CheckBox.Checked = true;
            //---------------Assert Precondition----------------
            Assert.IsTrue(projectNameControl.TextBox.Enabled);
            //---------------Execute Test ----------------------
            projectNameControl.CheckBox.Checked = false;
            //---------------Test Result -----------------------
            Assert.IsFalse(projectNameControl.TextBox.Enabled);
        }
    }
}